<template>
	<div>
		<city-header></city-header>
		<city-search :cities="cities"></city-search>
		<city-list :hotCities="hotCities" :cities="cities" :letter="letter"></city-list>
		<city-alphabet 
		:cities="cities" 
		@change="handleLetterChange"	
		></city-alphabet>
	</div>
</template>
<script>
import axios from 'axios'
import CityHeader from './components/header'
import CitySearch from './components/search'
import CityList from './components/list'
import CityAlphabet from './components/alphabet'

export default{
	name: "city",
	data () {
		return {
			hotCities: [],
			cities: {},
			letter: ''
		}
	},
	components: {
		'CityHeader': CityHeader,
		'CitySearch': CitySearch,
		'CityList': CityList,
		"CityAlphabet":CityAlphabet
	},
	methods: {
		getCityInfo () {
			axios.get('/api/city.json')
			.then(this.handleGetCityInfoSucc)
		},
		handleGetCityInfoSucc (res) {
			const data = res.data
 			if (data.ret && data.data) {
				this.hotCities = data.data.hotCities
				this.cities = data.data.cities
			}
		},
		handleLetterChange (letter) {
			this.letter = letter
		}
	},
	mounted () {
		this.getCityInfo()
	}
}
</script>
<style lang="stylus" scoped>
	
</style>